package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Tableorder;
import com.restaurant.service.TableorderService;

public class TableorderServiceImpl implements TableorderService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableorder addOrModify( Tableorder objTableorder ) {
       return ( Tableorder ) hibernateTemplate.merge( objTableorder );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableorder deleteRecord( Tableorder objTableorder ) {
       hibernateTemplate.delete( objTableorder );
       return objTableorder;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableorder modifyRecord( Tableorder objTableorder ) {
       return ( Tableorder ) hibernateTemplate.merge( objTableorder );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Tableorder> loadAll() {
       return (List<Tableorder>)hibernateTemplate.findByNamedQuery( "Tableorder.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableorder loadByPrimaryKey( Long primaryKey ) {
       return (Tableorder) hibernateTemplate.get( Tableorder.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Tableorder deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Tableorder> loadByHql(String query) {
       return ( List<Tableorder> ) hibernateTemplate.find( query );
   }
}